<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: "App",
  metaInfo() {
    return {
      title:
        this.$store.state.settings.dynamicTitle &&
        this.$store.state.settings.title,
      titleTemplate: (title) => {
        return title
          ? `${title} - ${process.env.VUE_APP_TITLE}`
          : process.env.VUE_APP_TITLE;
      },
    };
  },
  // 监听路由变化
  watch: {
    $route: {
      handler(to, from) {
        // 当用户登录成功后，获取枚举值
        if (this.$store.state.user.token) {
          const enums = this.$store.state.enums;

          if (Object.keys(enums).length === 0) {
            this.$store.dispatch("getMap");
          }
        }
      },
    },
  },
};
</script>
